﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DSS_Simplex
{
    public partial class Report1 : Form
    {
        public int counter=0;
        public Report1()
        {
            InitializeComponent();
            showIteration(counter);
            
        }
        
        private void bnext_Click(object sender, EventArgs e)
        {
            counter++;
            showIteration(counter);
        }

        private void bprev_Click(object sender, EventArgs e)
        {
            counter--;
            showIteration(counter);
        }

        private void showIteration(int counter)
        { 
            List<double[,]> list = Mesin.ListRepValue;
            List<string[]> listBasis = Mesin.ListBasisVar;

            string[] BasisVar = Mesin.ArrBasisVar;
            string[] NonBasisVar = Mesin.ArrNonBasisVar;

            Console.WriteLine("jumlah list: ");
            Console.Write(list.Count());
            Console.WriteLine("counter: ");
            Console.Write(counter);
            Console.WriteLine("ini var basis: ");
            for (int i = 0; i < BasisVar.Count(); i++) 
            {
                Console.Write(BasisVar[i] + "   ");
            }
            Console.WriteLine();
                //kondisi button
                if (counter == 0)
                {
                    bprev.Enabled = false;
                    bnext.Enabled = true;
                }
                else if (counter == list.Count() - 1)
                {
                    bnext.Enabled = false;
                    bprev.Enabled = true;
                }
                else
                {
                    bprev.Enabled = true;
                    bnext.Enabled = true;
                }

            DGiterasi.Rows.Clear();
            //fill DGV
            DGiterasi.RowCount = list.ElementAt(0).GetLength(0)+1;
            DGiterasi.ColumnCount = list.ElementAt(0).GetLength(1) + 1;

            //fill header
            string[] arrReport = Mesin.ArrRep;
            string[] arrReportHeader = Mesin.ArrRepHeader;

            Console.WriteLine("jml arr rep header: ");
            Console.Write(arrReportHeader.Count());
            Console.WriteLine("jml colmn count: ");
            Console.Write(DGiterasi.ColumnCount);

            DGiterasi.Columns[1].Name = "Nilai optimum";
            DGiterasi.Columns[1].DefaultCellStyle.BackColor = Color.RoyalBlue;
            DGiterasi.DefaultCellStyle.SelectionBackColor = Color.PowderBlue;
            DGiterasi.Rows[0].Cells[0].Value = "Z";
            DGiterasi.Rows[0].DefaultCellStyle.BackColor = Color.PeachPuff;
            DGiterasi.Columns[0].DefaultCellStyle.BackColor = Color.PeachPuff;
            
            for (int i = 0; i < NonBasisVar.Count(); i++)
            {
                DGiterasi.Columns[i + 2].Name = NonBasisVar[i];
            }
            for (int i = 0; i < BasisVar.Count(); i++)
            {
                DGiterasi.Rows[i+1].Cells[0].Value = listBasis.ElementAt(counter)[i];
                
            }
            //bold
            /*DataGridViewCellStyle style = new DataGridViewCellStyle();
            style.Font = new Font(DGiterasi.Font, FontStyle.Bold);
            DGiterasi.Rows[0].DefaultCellStyle = style;
            DGiterasi.Columns[1].DefaultCellStyle = style;*/
            
            //isi DVG
            for (int ii = 0; ii < list.ElementAt(counter).GetLength(0); ii++)
            {
                for (int jj = 0; jj < list.ElementAt(counter).GetLength(1); jj++)
                {
                    Console.Write("" + list.ElementAt(counter)[ii, jj]);
                    DGiterasi.Rows[ii].Cells[jj + 1].Value = list.ElementAt(counter)[ii, jj];
                }
            }
            //autosize DG
            for (int i = 0; i < DGiterasi.ColumnCount; i++) 
            {
                DGiterasi.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }
            
        }
    }
}
